import request from "@/utils/request";
import config from "@/config";
import {
	getToken
} from "@/utils/auth";
const baseUrl = config.baseUrl;
// 二维码
export function getQrcodeImg(data) {
	return request({
		url: `https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=${encodeURIComponent(
      data
    )}`,
		headers: {
			isToken: false,
		},
		baseUrl: "https://mp.weixin.qq.com",
		method: "get",
	});
}
export function getQrcode(data) {
	return request({
		url: "/wx/mp/qrcode",
		headers: {
			isToken: true,
		},
		method: "post",
		data: data,
	});
}
// 上传
export function uploadImage(file, client, token = '') {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: baseUrl + `/oss/image/MASTER`,
			filePath: file,
			name: "file",
			header: {
				Authorization: getToken() ? "Bearer " + getToken() : "Bearer " + token,
			},
			success: async (uploadFileRes) => {
				resolve(uploadFileRes);
			},
			fail: async (err) => {
				reject(err);
			},
		});
	});
}
// 无损上传
export function uploadImageWX(file, client, token = '') {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: baseUrl + `/oss/image/lossless/MASTER`,
			filePath: file,
			name: "file",
			header: {
				Authorization: getToken() ? "Bearer " + getToken() : "Bearer " + token,
			},
			success: async (uploadFileRes) => {
				resolve(uploadFileRes);
			},
			fail: async (err) => {
				reject(err);
			},
		});
	});
}
// 轮播图
export function carousel_images(data) {
	return request({
		url: "/tennis/carousel_images/list",
		headers: {
			isToken: false,
		},
		method: "get",
		params: data,
	});
}
// 微信回调
export function oauth2(data) {
	return request({
		url: "/wx/mp/login_token",
		headers: {
			isToken: true,
		},
		method: "get",
		params: data,
	});
}
// 系统设置
export function getConfig(data) {
	return request({
		url: "/tennis/system/" + data,
		headers: {
			isToken: false,
		},
		method: "get",

	});
}